package com.fun.wyunfei.timeline.util;

import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.view.ViewGroup;

/**
 * create by author vvyunfei on 2018/11/16 12
 */
public class SnackbarUtil {

    public static void show(View view, String text) {
        Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
        snackbar.show();
    }

    public static void show(View view, String text, String btnText, Runnable runnable) {

        Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
        snackbar.setAction(btnText, v1 -> runnable.run()).show();
    }

    public static void show(View view, String text, int gravity) {
        Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
        View v = snackbar.getView();
        ViewGroup.LayoutParams vl = v.getLayoutParams();
        CoordinatorLayout.LayoutParams cl = new CoordinatorLayout.LayoutParams(vl.width, vl.height);
        //设置显示位置
        cl.gravity = gravity;
        v.setLayoutParams(cl);
        snackbar.show();
    }

    public static void show(View view, String text, int gravity, String btnText, Runnable runnable) {
        Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
        View v = snackbar.getView();
        ViewGroup.LayoutParams vl = v.getLayoutParams();
        CoordinatorLayout.LayoutParams cl = new CoordinatorLayout.LayoutParams(vl.width, vl.height);
        //设置显示位置
        cl.gravity = gravity;
        v.setLayoutParams(cl);
        snackbar.setAction(btnText, v1 -> runnable.run()).show();
    }


    //        View v = snackbar.getView();
//        ViewGroup.LayoutParams vl = v.getLayoutParams();
//        CoordinatorLayout.LayoutParams cl = new CoordinatorLayout.LayoutParams(vl.width, vl.height);
    //设置字体为红色
//        ((TextView) v.findViewById(R.id.snackbar_text)).setTextColor(Color.RED);
    //设置显示位置居中
//        cl.gravity = Gravity.TOP;
//        v.setLayoutParams(cl);
    //设置背景色为绿色
//        v.setBackgroundColor(Color.GREEN);
    //自定义动画
    //v.setAnimation();
    //设置icon
//        ImageView iconImage = new ImageView(context);
//        iconImage.setImageResource(R.mipmap.ic_launcher);
    //icon插入布局
//        Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) v;
//        snackbarLayout.addView(iconImage, 0);
    //设置按钮为蓝色
//        .setActionTextColor(Color.BLUE)
//        snackbar.show();

}
